package com.ruoyi.web.controller.carbon;

import com.ruoyi.carbon.domain.vo.BuhuoShenqingVo;
import com.ruoyi.carbon.entity.BuhuoShenqing;
import com.ruoyi.carbon.service.BuhuoShenqingService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@Anonymous
@RequestMapping("/carbon/buhuoShenqing")
public class BuhuoShenqingController extends BaseController {

    @Autowired
    private BuhuoShenqingService buhuoShenqingService;


    @GetMapping("/list")
    public TableDataInfo list(BuhuoShenqing buhuoShenqing) {
        startPage();
        List<BuhuoShenqing> list = buhuoShenqingService.list(buhuoShenqing);
        return getDataTable(list);
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable List<Long> ids) {
        int num = buhuoShenqingService.remove(ids);
        return num <= 0 ? error("删除失败") : success("删除成功");
    }

    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable Long id) {
        BuhuoShenqingVo buhuoShenqingVo = buhuoShenqingService.getById(id);
        return success(buhuoShenqingVo);
    }

    @PutMapping
    public AjaxResult edit(@Valid @RequestBody BuhuoShenqingVo buhuoShenqingVo) {
        int num = buhuoShenqingService.edit(buhuoShenqingVo);
        return num <= 0 ? error("修改失败") : success("修改成功");
    }
}
